{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-06-10T03:02:34.505212Z",
     "start_time": "2025-06-10T03:02:34.501685Z"
    }
   },
   "source": [
    "# 导包\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import warnings\n",
    "\n",
    "warnings.filterwarnings('ignore')\n",
    "pd.set_option('display.max_columns', None)"
   ],
   "outputs": [],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-10T03:02:35.909365Z",
     "start_time": "2025-06-10T03:02:35.096425Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 读取数据\n",
    "train_df = pd.read_csv('data/train.csv', parse_dates=['auditing_date', 'due_date', 'repay_date'])"
   ],
   "id": "162e594ef70d84f9",
   "outputs": [],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-06-10T03:08:09.798003Z",
     "start_time": "2025-06-10T03:02:36.497649Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 初始化多个列表用于存储不同的特征列数据\n",
    "l0 = []  # 存储 user_id\n",
    "l1 = []  # 存储 listing_id\n",
    "l2 = []  # 存储 auditing_date\n",
    "l3 = []  # 存储 due_date\n",
    "l4 = []  # 存储 now（生成的 repay_date）\n",
    "\n",
    "# 计数器变量 c，记录处理了多少条数据\n",
    "c = 0\n",
    "\n",
    "# 遍历训练数据集中的每一行\n",
    "for j in range(train_df.shape[0]):\n",
    "    # 提取当前行的各个字段值\n",
    "    ui = train_df['user_id'].values[j]      # 用户 ID\n",
    "    li = train_df['listing_id'].values[j]   # 列表 ID\n",
    "    ad = train_df['auditing_date'].values[j]  # 审核日期\n",
    "    due = train_df['due_date'].values[j]    # 截止日期\n",
    "    \n",
    "    out = 0  # 循环标志变量，控制内层循环是否继续\n",
    "    now = ad  # 设置 now 初始值为审核日期\n",
    "    \n",
    "    # 内层循环：生成从审核日期开始直到截止日期 + 1 天的所有日期\n",
    "    while out == 0:\n",
    "        # 将当前行的信息重复添加到各自的列表中\n",
    "        l0.append(ui)\n",
    "        l1.append(li)\n",
    "        l2.append(ad)\n",
    "        l3.append(due)\n",
    "        l4.append(now)  # now 是当前生成的日期\n",
    "        \n",
    "        # now 增加一天\n",
    "        now = now + np.timedelta64(1, 'D')\n",
    "        \n",
    "        # 如果 now 超过了 due + 1 天，则结束循环，并增加计数器 c\n",
    "        if now > due + np.timedelta64(1, 'D'):\n",
    "            out = 1\n",
    "            c = c + 1  # 每当一个完整的日期序列生成完毕时，计数器增加\n",
    "    \n",
    "    # 每处理 10000 条数据，打印进度信息\n",
    "    if c % 10000 == 0:\n",
    "        # 显示已处理的数据条数和总数据量\n",
    "        print(c, '/', train_df.shape[0])  "
   ],
   "id": "d977ca874b553960",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10000 / 1000000\n",
      "20000 / 1000000\n",
      "30000 / 1000000\n",
      "40000 / 1000000\n",
      "50000 / 1000000\n",
      "60000 / 1000000\n",
      "70000 / 1000000\n",
      "80000 / 1000000\n",
      "90000 / 1000000\n",
      "100000 / 1000000\n",
      "110000 / 1000000\n",
      "120000 / 1000000\n",
      "130000 / 1000000\n",
      "140000 / 1000000\n",
      "150000 / 1000000\n",
      "160000 / 1000000\n",
      "170000 / 1000000\n",
      "180000 / 1000000\n",
      "190000 / 1000000\n",
      "200000 / 1000000\n",
      "210000 / 1000000\n",
      "220000 / 1000000\n",
      "230000 / 1000000\n",
      "240000 / 1000000\n",
      "250000 / 1000000\n",
      "260000 / 1000000\n",
      "270000 / 1000000\n",
      "280000 / 1000000\n",
      "290000 / 1000000\n",
      "300000 / 1000000\n",
      "310000 / 1000000\n",
      "320000 / 1000000\n",
      "330000 / 1000000\n",
      "340000 / 1000000\n",
      "350000 / 1000000\n",
      "360000 / 1000000\n",
      "370000 / 1000000\n",
      "380000 / 1000000\n",
      "390000 / 1000000\n",
      "400000 / 1000000\n",
      "410000 / 1000000\n",
      "420000 / 1000000\n",
      "430000 / 1000000\n",
      "440000 / 1000000\n",
      "450000 / 1000000\n",
      "460000 / 1000000\n",
      "470000 / 1000000\n",
      "480000 / 1000000\n",
      "490000 / 1000000\n",
      "500000 / 1000000\n",
      "510000 / 1000000\n",
      "520000 / 1000000\n",
      "530000 / 1000000\n",
      "540000 / 1000000\n",
      "550000 / 1000000\n",
      "560000 / 1000000\n",
      "570000 / 1000000\n",
      "580000 / 1000000\n",
      "590000 / 1000000\n",
      "600000 / 1000000\n",
      "610000 / 1000000\n",
      "620000 / 1000000\n",
      "630000 / 1000000\n",
      "640000 / 1000000\n",
      "650000 / 1000000\n",
      "660000 / 1000000\n",
      "670000 / 1000000\n",
      "680000 / 1000000\n",
      "690000 / 1000000\n",
      "700000 / 1000000\n",
      "710000 / 1000000\n",
      "720000 / 1000000\n",
      "730000 / 1000000\n",
      "740000 / 1000000\n",
      "750000 / 1000000\n",
      "760000 / 1000000\n",
      "770000 / 1000000\n",
      "780000 / 1000000\n",
      "790000 / 1000000\n",
      "800000 / 1000000\n",
      "810000 / 1000000\n",
      "820000 / 1000000\n",
      "830000 / 1000000\n",
      "840000 / 1000000\n",
      "850000 / 1000000\n",
      "860000 / 1000000\n",
      "870000 / 1000000\n",
      "880000 / 1000000\n",
      "890000 / 1000000\n",
      "900000 / 1000000\n",
      "910000 / 1000000\n",
      "920000 / 1000000\n",
      "930000 / 1000000\n",
      "940000 / 1000000\n",
      "950000 / 1000000\n",
      "960000 / 1000000\n",
      "970000 / 1000000\n",
      "980000 / 1000000\n",
      "990000 / 1000000\n",
      "1000000 / 1000000\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "# 创建一个 DataFrame，并将生成的特征列数据添加到 DataFrame 中\n",
    "data = pd.DataFrame()\n",
    "data['user_id'] = l0\n",
    "data['listing_id'] = l1\n",
    "data['auditing_date'] = l2\n",
    "data['due_date'] = l3\n",
    "data['repay_date'] = l4\n",
    "# 保存数据\n",
    "data.to_csv('result_data/newlist.csv', index=False)"
   ],
   "id": "89629ec3d511df9f"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
